package com.evil.kingdom.pojo.entity.action;

import cn.hutool.core.collection.ListUtil;
import com.evil.kingdom.utils.DijkstraUtil;

import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/**
 * 战场布局
 *
 * @author liyang
 * @date 2024-07-04 16:55
 */
public class BattleLayout extends ConcurrentHashMap<BattlePerson<?>, AbstractPosition> {

    /**
     * 指定坐标是否在战场内每个布局指定范围内
     *
     * @param position position
     * @param unit unit
     * @return boolean
     */
    public boolean nearest(AbstractPosition position, double unit, AbstractPosition...ignore) {
        return this.values().stream().filter(e -> !ListUtil.toList(ignore).contains(e)).anyMatch(e -> DijkstraUtil.calWeight(e, position, 1d) <= unit);
    }

    public String printInfo() {
        return this.entrySet().stream().map(entey -> String.format("%s:%s", entey.getKey().getBase().getName(), entey.getValue().simple())).collect(Collectors.joining(","));
    }
}
